package com.xiaoxi.bms.controller.common;

import com.xiaoxi.bms.common.constant.enumeration.statuscode.user.RegisterUserEnums;
import com.xiaoxi.bms.common.response.ApiResponse;
import com.xiaoxi.bms.domain.password.CheckResult;
import com.xiaoxi.bms.domain.password.VerifyPassword;
import com.xiaoxi.bms.service.common.password.CheckPasswordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @Author xiaoxi
 * @ProjectName springcloudbms
 * @PackageName com.xiaoxi.checkpassword.controller
 * @ClassName CheckPasswordController
 * @Description TODO
 * @Date 2023/2/8 19:04
 * @Version 1.0
 */
@RestController
@RequestMapping("/password/api/v1")
@Slf4j
public class CheckPasswordController {

    @Resource
    private CheckPasswordService checkPasswordService;

    @PostMapping("verify")
    public ApiResponse verifyPassword(@RequestBody VerifyPassword verifyPassword) {
        CheckResult checkResult = checkPasswordService.checkPassword(verifyPassword);
        if (Objects.nonNull(checkResult.getConclusion())) {
            return ApiResponse.ofMessage(RegisterUserEnums.PASSWORD_TOO_SIMPLE.getCode(), checkResult.getConclusion());
        }
        return ApiResponse.ofSuccess();
    }

}
